package modeles;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Utilisateur {
	int user_id;
	String nom;
	String login;
	String passwd;
	public int getUser_id() {
		return user_id;
	}
	public void setUser_id(int user_id) {
		this.user_id = user_id;
	}
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPasswd() {
		return passwd;
	}
	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}
	
	public Utilisateur(){
		this.nom = "";
		this.login = "";
		this.passwd = "";
		
	}
	public Utilisateur(int user_id, String nom, String login, String passwd) {
		super();
		this.user_id = user_id;
		this.nom = nom;
		this.login = login;
		this.passwd = passwd;
	}

	public Utilisateur existUser(DBManager _dbManager){
    	Utilisateur bUser = null;
    	String zQueryUser = "SELECT * FROM \"UTILISATEUR\" where user_login='"+this.login+"' and user_passwd = '"+this.passwd+"'";
    	
		try
		{
			Statement oStmtUser = (Statement) _dbManager.oStockDbCnx.createStatement () ;	
			ResultSet oRsUser = (ResultSet) oStmtUser.executeQuery (zQueryUser) ;
			if (oRsUser.next ())
			{
				bUser = new Utilisateur();
				bUser.setUser_id(oRsUser.getInt("user_id"));
				bUser.setNom(oRsUser.getString("user_name"));
				bUser.setLogin(oRsUser.getString("user_login"));
				bUser.setPasswd(oRsUser.getString("user_passwd"));
				
			}
		}
		catch (SQLException _e)
		{
			System.out.println ("Erreur interne pendant la requete !") ;
			_e.printStackTrace () ;
		}
    	return bUser;
    }
}
